package com.simba.server.commands.impl.update;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;
import com.simba.server.components.data.BasicConfig;

public class RenewBasicConfigCmd implements ICommand
{
	public static final String NAME = "RenewBasicConfigCmd";
	private final BasicConfig basicConfig;
	private final String sql = "update tt_basic_config set basicValue=? where basicKey=?;";

	public RenewBasicConfigCmd(BasicConfig basicConfig)
	{
		this.basicConfig = basicConfig;
	}

	@Override
	public String getName()
	{
		return RenewBasicConfigCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;

			dbOperator.prepareStatement(this.sql);

			dbOperator.setString(1, this.basicConfig.getBasicValue());
			dbOperator.setString(2, this.basicConfig.getBasicKey());

			int rs = dbOperator.executeUpdate();
			if (rs > 0)
			{
				ret = true;
			}
			else
			{
				ret = false;
			}
		}
		catch (Exception ex)
		{
			ret = false;
		}

		return ret;
	}

}
